<?php
declare(strict_types=1);

namespace Dreamcat\Http\EnhanceClient\Impl;

use Dreamcat\Http\EnhanceClient\ResponseDecoderInterface;
use RuntimeException;

/**
 * json解码器
 * @author vijay
 */
class JsonDecoder implements ResponseDecoderInterface
{
    /**
     * @inheritDoc
     */
    public function decodeResponse(string $responseStr)
    {
        $data = json_decode($responseStr, true);
        $error = json_last_error();
        if ($error) {
            throw new RuntimeException("响应数据解码失败：" . json_last_error_msg(), json_last_error());
        }
        return $data;
    }
}

# end of file
